home *** CD-ROM | disk | FTP | other *** search
/ MacTech 1 to 12 / MacTech-vol-1-12.toast / Source / MacTech® Magazine / Volume 04 - 1988 / 04.09 Sep 88 / PopMenus Source / PopMenus.p < prev    next >
Encoding:
Text File  |  1988-04-24  |  2.3 KB  |  105 lines  |  [TEXT/MPS ]

  1. (*****************************************************
  2. Pop-up Menu Example
  3. *****************************************************)
  4.  
  5. PROGRAM PopMenus;
  6.  
  7. USES MemTypes,
  8.     Quickdraw,
  9.     OSIntf,
  10.     ToolIntf,
  11.     PackIntf;
  12.  
  13. CONST
  14.     myDLOGid     = 128;        { DLOG resource ID    }
  15.     
  16.     Activate    =    2;        { Activate button        }    
  17.     PopMenu1    =    3;        { popMenu control 1    }    
  18.     PopMenu2    =    4;        { popMenu control 2    }    
  19.     PopMenu3    =    5;        { popMenu control 3    }
  20.     
  21.     ON            =    0;        { for HiliteControl        }
  22.     OFF        = 255;        { for HiliteControl        }
  23.  
  24.  
  25. VAR
  26.     myDialog:    DialogPtr;    { our test dialog            }
  27.     itemHit:    INTEGER;    { user's choice            }
  28.     state:        INTEGER;    { ON or OFF            }
  29.  
  30.  
  31.  
  32.  
  33. (*****************************************************
  34. doHitActivate: Toggles the activation state of the
  35.     popMenu control.  Also toggles the Activate
  36.     button's title (Activate <=> Deactivate).
  37. *****************************************************)
  38.  
  39. PROCEDURE doHitActivate(dPtr: DialogPtr;
  40.             VAR state: INTEGER);
  41. VAR
  42.     ik:    INTEGER;
  43.     ih:    Handle;
  44.     ib:    Rect;
  45.  
  46. BEGIN
  47.     { get handle to Activate button }
  48.     GetDItem(dPtr, Activate, ik, ih, ib);
  49.     
  50.     { toggle state variable and button title }
  51.     if (state = ON) then
  52.         begin
  53.             state := OFF;
  54.             SetCTitle(ControlHandle(ih), 'Activate');
  55.         end
  56.     else begin
  57.         state := ON;
  58.         SetCTitle(ControlHandle(ih), 'Deactivate');
  59.     end;
  60.     
  61.     { toggle the popMenu controls' activation states }
  62.     GetDItem(dPtr, PopMenu1, ik, ih, ib);
  63.     HiliteControl(ControlHandle(ih), state);
  64.  
  65.     GetDItem(dPtr, PopMenu2, ik, ih, ib);
  66.     HiliteControl(ControlHandle(ih), state);
  67.     
  68.     GetDItem(dPtr, PopMenu3, ik, ih, ib);
  69.     HiliteControl(ControlHandle(ih), state);
  70.  
  71. END;  { doHitActivate }
  72.  
  73.  
  74.  
  75. (*****************************************************
  76. Main
  77. *****************************************************)
  78.  
  79. BEGIN
  80.     { perform the ritual incantation }
  81.     InitGraf(@thePort);    
  82.     InitFonts;            
  83.     FlushEvents(everyEvent, 0);
  84.     InitWindows;                
  85.     InitMenus;            
  86.     TEInit;
  87.     InitDialogs(NIL);            
  88.     InitCursor;            
  89.  
  90.     { read in the dialog from its resource template }
  91.     myDialog := GetNewDialog(myDLOGid, NIL,
  92.                                 POINTER(-1));
  93.     
  94.     { cycle through ModalDialog() until itemHit = OK }
  95.     REPEAT
  96.         ModalDialog(NIL, itemHit);
  97.         
  98.         { if the user hit the activate button, toggle }
  99.         IF (itemHit = Activate) THEN BEGIN
  100.             doHitActivate(myDialog, state);
  101.         END;
  102.     UNTIL itemHit = OK;
  103.     
  104.     DisposDialog(myDialog);
  105. END.  { program PopMenus }